import 'package:dio/dio.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:retrofit/retrofit.dart';
import 'package:s_k_todo/data/base_data.dart';

import '../data/const.dart';

part 'user_model.g.dart';

@RestApi(baseUrl: BASE_URL)
abstract class UserApi {
  factory UserApi(Dio dio,{String? baseUrl}) = _UserApi;

  @POST("/user/login")
  Future<BaseData<TokenData>> login(@Field("phone") String phone, @Field("password") String password);

  @POST("/user/register")
  Future<BaseData<String>> register(@Field("phone") String phone, @Field("password") String password);

  @GET("/user/getUserInfo")
  Future<BaseData<UserData>> getUserInfo(@Header("id") String id);
}

class LoginData {
  String? phone;
  String? password;

  LoginData({this.phone, this.password});
}

@JsonSerializable()
class UserData {
  String? phone;
  String? nicName;
  String? id;

  UserData({this.phone, this.nicName, this.id});

  factory UserData.fromJson(Map<String, dynamic> json) =>
      _$UserDataFromJson(json);

  Map<String, dynamic> toJson() => _$UserDataToJson(this);
}
@JsonSerializable()
class TokenData {
  String? refreshToken;
  String? accessToken;

  TokenData({this.refreshToken, this.accessToken});
  factory TokenData.fromJson(Map<String, dynamic> json) =>
      _$TokenDataFromJson(json);
  Map<String, dynamic> toJson() => _$TokenDataToJson(this);
}